package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Resource;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-06-01 22:05
 */
@Api(tags = "后台管理系统[资源模块]")
@RequestMapping("/admin")
@RestController
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @SystemLog(notes = "获取资源模块列表{后台管理系统}")
    @ApiOperation(value = "获取资源模块列表接口",notes = "获取资源模块列表 { 二级列表 }")
    @GetMapping("/role/resources")
    public ResponseResult getResources(){
        return resourceService.getResources();
    }


    @SystemLog(notes = "获取资源模块列表{后台管理系统}")
    @ApiOperation(value = "获取资源模块列表接口",notes = "获取资源模块列表{资源管理菜单}")
    @GetMapping("/resources")
    public ResponseResult getResourceList(@RequestParam(value = "keywords",required = false)String keywords){
        return resourceService.getResourceList(keywords);
    }


    @SystemLog(notes = "新增资源模块{后台管理系统}")
    @ApiOperation(value = "新增资源模块接口")
    @PostMapping("/resources")
    public ResponseResult addResource(@RequestBody Resource resource){
        return resourceService.addResource(resource);
    }


    @SystemLog(notes = "更新资源模块匿名访问状态{后台管理系统}")
    @ApiOperation(value = "更新资源模块匿名访问状态接口")
    @PutMapping("/resources/anonymous/{resourceId}")
    public ResponseResult isAnonymous(@PathVariable("resourceId") Integer resourceId,
                                      @RequestParam("isAnonymous")Integer isAnonymous)
    {
        return resourceService.isAnonymous(resourceId,isAnonymous);
    }

    @SystemLog(notes = "删除资源模块{后台管理系统}")
    @ApiOperation(value = "删除资源模块接口")
    @DeleteMapping("/resources")
    public ResponseResult deleteResource(@RequestBody Integer[] resourceIdList){
        return resourceService.deleteResource(resourceIdList);
    }



}
